void AdjustDown(int* a, int length, int parent) //现在是建大堆
{
	int child = parent * 2 + 1;
	while (child < length)
	{
		if (child + 1 < length && a[child] < a[child + 1])
		{
			child++;
		}
		if (a[parent] < a[child])
		{
			Swap(&a[parent], &a[child]);
			parent = child;
			child = parent * 2 + 1;
		}
		else
		{
			break;
		}
	}
}
void HeapSort(int* arr, int length) //升序建大堆，降序建小堆
{
	assert(arr);
	for (int i = (length - 1 - 1) / 2; i >= 0; i--)
	{
		AdjustDown(arr, length, i);
	}
	
	int end = length - 1;
	while (end)
	{
		Swap(&arr[0],&arr[end]);
		AdjustDown(arr, end, 0);
		end--;
	}
}